package com.unicampmaps;


import java.util.ArrayList;
import java.util.Collection;
import java.util.ConcurrentModificationException;
import java.util.concurrent.CopyOnWriteArrayList;

import org.mapsforge.android.maps.MapView;
import org.mapsforge.android.maps.overlay.OverlayItem;

import android.app.Activity;
import android.content.res.Resources;


/**
 * Sample illustrating {@link BalloonItemizedOverlay} use. We are using
 * {@link OverlayItem} to parametrize {@link BalloonItemizedOverlay}, you'll
 * probably want to have some more specific type there, something like
 * MyOwnOverlayItem which extends {@link OverlayItem}.
 * 
 * @author isaac.salgueiro@discalis.com
 * 
 */
public class SampleBalloonItemizedOverlay extends BalloonItemizedOverlay<OverlayItem> {

	private ArrayList<OverlayItem> m_overlays = new ArrayList<OverlayItem>();
        
		/**
         * Overlay constructor. Usually you'll build this overlay with a reference
         * to a {@link MapView} or an {@link Activity} containing a {@link MapView}.
         * 
         * @param resources
         *            {@link Resources} used to get the drawable. Tipically a
         *            reference to {@link Activity#getResources()}
         * @param mapView
         */
        public SampleBalloonItemizedOverlay(MapView mapView) {
                // Initializes the Overlay. Each OverlayItem will be drawn with this
                // drawable.
                super(boundCenterBottom(mapView.getContext().getResources().getDrawable(R.drawable.circle)), mapView);
        }

        /**
         * Returning just one static item.
         */
        @Override
        protected OverlayItem createItem(int i) {
        	System.out.println(i);
        	return this.m_overlays.get(i);
            /*final GeoPoint somePosition = BasicMapViewer.RU;
            final OverlayItem ovelayItem = new OverlayItem(somePosition, "Restaurante Acadêmico",
                            "\"Bandeco\"");
            return ovelayItem;*/
        }

        /**
         * Just one single static item...
         * <p>
         * You're probably backing your {@link OverlayItem}s in some
         * {@link Collection}, so this method will return the size of that
         * {@link Collection}.
         * </p>
         * <p>
         * Please, take <i>thread safeiness</i> in consideration on your
         * implementation. Something like {@link CopyOnWriteArrayList} may be very
         * usefull avoiding {@link ConcurrentModificationException}s...
         * </p>
         * 
         * @see #createItem(int);
         */
        @Override
        public int size() {
        	return m_overlays.size();
        }
        
        public void addOverlay(OverlayItem overlay) {
    	    m_overlays.add(overlay);
    	    populate();
    	}
}